<?php
defined('BASEPATH') OR exit ('No direct script access allowed');

require (APPPATH . '/libraries/REST_Controller.php');
include_once 'db_functions_account.php';
class register extends REST_Controller {

	function user_get() {
		echo "only support method post";

	}

	function user_post() {
		// get account from client with post method;
		$username = $this->post('username');
		$password = $this->post('password');
		$name = $this->post('name');
		$email = $this->post('email');
		$gcm_regid = $this->post('gcm_regid');

		$code = null;
		$result = null;

		$db = new db_functions_account();
		// check user exits in db
		$isExitsAcount = $db->checkUserExisted($username);
		if ($isExitsAcount) {
			$code = -1;
			$result = "Error! This account exist!";
		} else {
			//user not exist, start save acount to db
			$isRegisterSucess = $db->registerNew($username, $password, $gcm_regid, $email, $name);
			if ($isRegisterSucess) {
				$code = 0;
				$result = "Register sucess!";
			} else {
				$code = -1;
				$result = "Register fall!";

			}

		}

		$re = array (
			'code' => $code,
			'result' => $result,
			'data' => "no data",

			
		);

		$this->response($re);

	}

}
?>
